//
//  AllBtnClickedView.m
//  Youhuiju
//
//  Created by 余尚飞 on 16/8/10.
//  Copyright © 2016年 yutenys. All rights reserved.
//

#import "AllBtnClickedView.h"
#import "AllBtnClickedViewTableViewCell.h"


@interface AllBtnClickedView ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong)UITableView *tableView;


//占位数据
@property(nonatomic,strong)NSArray *dataArray;

@end


@implementation AllBtnClickedView

static NSString *AllBtnClickedViewTableViewCellIden = @"AllBtnClickedViewTableViewCellIden";
static id _sharedInstance = nil;
+(instancetype)getInstance
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _sharedInstance = [[self alloc]init];
    });
    return _sharedInstance;
}

-(instancetype)initWithFrame:(CGRect)frame
{
    _sharedInstance = [super initWithFrame:frame];

    [self creatView];
    
    return _sharedInstance;
}

-(void)creatView
{
    
    self.dataArray = @[@"母婴",@"办公用品",@"服装",@"生鲜",@"酒水文化",@"日化"];
    self.tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.backgroundColor = [UIColor clearColor];
    self.tableView.layer.cornerRadius = 5 * FitH;
    [self.tableView setSeparatorColor:[UIColor clearColor]];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.scrollEnabled = NO;
    [self.tableView registerNib:[UINib nibWithNibName:@"AllBtnClickedViewTableViewCell" bundle:nil] forCellReuseIdentifier:AllBtnClickedViewTableViewCellIden];
    [self addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 0, 0));
//        make.left.equalTo(self.mas_left);
//        make.right.equalTo(self.mas_right);
//        make.top.equalTo(self.mas_top);
//        make.bottom.equalTo(self.mas_bottom);
    }];
}

#pragma mark -------- tableView delegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArray.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 24 * FitH;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    AllBtnClickedViewTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:AllBtnClickedViewTableViewCellIden forIndexPath:indexPath];
    cell.dataString = self.dataArray[indexPath.row];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    self.hidden = YES;
     [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
    [self.clikedCellDelegate clickedCellChangeTitle:self.dataArray[indexPath.row]];
}


@end
